package nowcode

import "fmt"

func MinPathSum(grid [][]int) int {
	n := len(grid)
	m := len(grid[0])

	for _, v := range grid {
		fmt.Println(v)
	}

	for i := 1; i < m; i++ {
		grid[0][i] += grid[0][i-1]
	}

	for i := 1; i < n; i++ {
		grid[i][0] += grid[i-1][0]
	}

	for i := 1; i < n; i++ {
		for j := 1; j < m; j++ {
			grid[i][j] += min(grid[i][j-1], grid[i-1][j])
		}
	}

	for _, v := range grid {
		fmt.Println(v)
	}

	return grid[n-1][m-1]
}
